#include <iostream>
#include <cstdio>
#include "lib.h"
using namespace std;

int main(int argc, char *argv[]) {
	if (argc < 4) {
		printf("%s: wrong number of arguments!\n", argv[0]);
		return 1;
	}
	int n = s_to_i(argv[2]);
	int m = s_to_i(argv[3]);
	if (n <= 0 || m <= 0) {
		printf("%s: error parsing integers!\n", argv[0]);
		return 1;
	}
	char *s = new char[m+10];
	FILE *f = fopen(argv[1], "r");
	if (f == NULL) {
		printf("%s: error while opening file!\n", argv[0]);
		return 1;
	}
	for (int i = 0; i < n; ++i) {
		int x;
		for(int j = 0; j < m; ++j) {
			do {x = fgetc(f);} while ((char)x == '\r');
			if (x == EOF || (char)x == '\n') {
				while (j < m) s[j++] = ' ';
				break;
			}
			//printf("%c", (char)x);
			s[j] = (char)x;
		}
		while ((char)x != '\n')
			x = fgetc(f);
		s[m] = '\0';
		printf("%s\n", s);
	}
	fclose(f);
	return 0;
}
